package com.tbb.app.common.utils;

import org.springframework.context.ApplicationContext;

/**
 * Spring上下文工具类
 *
 * @author LiuSenLin
 * @date 2020/2/28 12:44
 */
public class SpringContextUtil {

    /**
     * Spring上下文
     */
    private static ApplicationContext applicationContext;

    public static void setApplicationContext(ApplicationContext applicationContext) {
        SpringContextUtil.applicationContext = applicationContext;
    }

    /**
     * 从上下文中根据类型获取Bean
     *
     * @param clazz
     * @param <T>
     * @return
     */
    public static <T> T getBean(Class<T> clazz) {
        return applicationContext.getBean(clazz);
    }
}
